package au.com.somethingwritten.model;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Date;

import org.junit.Test;

public class OrderDAOTest {
	

	@Test
	public void testInsertOrder() {
		Payment tmpPayment = new Payment("visa", "0987-9087-0987-9087", new Date(), 212, "John Smith", "123 fake street", "city", "state", 2615);
		
		ArrayList<CartItem> items = new ArrayList<CartItem>();
		items.add(new CartItem(new Book(1, null, null, null, null, 12.00, 0, null, 0, 0, null, null), 3));
		items.add(new CartItem(new Book(2, null, null, null, null, 8.50, 0, null, 0, 0, null, null), 3));
		
		Order testOrder = new Order(new Date(), 1, "123 fake street", "city", "state", 2615, tmpPayment, "Sent", "test@example.com", items);
		
		//update database 
		int numRows = 0;
		try{
			numRows = OrderDAO.insertOrder(testOrder);
		}catch(Exception updateErr){
			fail(updateErr.getMessage());
		}
		
		if(numRows < 1){
			fail("No rows updated");
		}
	}

}
